fix: resolve RN 0.85 web warnings and upgrade Expo SDK 56#4958
fix: resolve RN 0.85 web warnings and upgrade Expo SDK 56#4958azizbecha wants to merge 1 commit into
Conversation
|
Hey @azizbecha, thank you for your pull request 🤗. The documentation from this branch can be viewed here. |
| tintColor={color} | ||
| fadeDuration={0} | ||
| style={{ width: size, height: size, tintColor: color }} | ||
| style={{ width: size, height: size }} |
There was a problem hiding this comment.
Where are you seeing warnings about tintColor? I only see warnings for resizeMode and shadow*
| it('uses boxShadow instead of shadow props on web headers', () => { | ||
| const originalPlatform = Platform.OS; | ||
| Platform.OS = 'web'; | ||
|
|
||
| try { | ||
| const { getByTestId } = render( | ||
| <mockSafeAreaContext.SafeAreaProvider> | ||
| <Appbar.Header elevated> | ||
| <Appbar.Content title="Examples" /> | ||
| </Appbar.Header> | ||
| </mockSafeAreaContext.SafeAreaProvider> | ||
| ); | ||
|
|
||
| const styles = StyleSheet.flatten( | ||
| getByTestId('appbar-header-root-layer').props.style | ||
| ); | ||
|
|
||
| expect(styles).toMatchObject({ | ||
| boxShadow: '0px 2px 6px rgba(0, 0, 0, 0.3)', | ||
| }); | ||
| expect(styles).not.toHaveProperty('shadowColor'); | ||
| expect(styles).not.toHaveProperty('shadowOpacity'); | ||
| expect(styles).not.toHaveProperty('shadowOffset'); | ||
| expect(styles).not.toHaveProperty('shadowRadius'); | ||
| } finally { | ||
| Platform.OS = originalPlatform; | ||
| } | ||
| }); |
There was a problem hiding this comment.
Remove this test. Tests shouldn't test implementation details.
To test for deprecated styles an appropriate test would be to actually check whether there are console warnings. Though I think that's not really necessary.
| it('passes image-specific props without using deprecated style keys', () => { | ||
| const tintColor = 'tomato'; | ||
| const source = { uri: 'https://picsum.photos/700' }; | ||
| const { getByTestId } = render( | ||
| <Icon | ||
| source={source} | ||
| size={ICON_SIZE} | ||
| color={tintColor} | ||
| testID="image-icon" | ||
| /> | ||
| ); | ||
| const imageIcon = getByTestId('image-icon'); | ||
| const styles = StyleSheet.flatten(imageIcon.props.style); | ||
|
|
||
| expect(imageIcon.props.resizeMode).toBe('contain'); | ||
| expect(imageIcon.props.tintColor).toBe(tintColor); | ||
| expect(styles).not.toHaveProperty('resizeMode'); | ||
| expect(styles).not.toHaveProperty('tintColor'); | ||
| }); |
| it('renders web shadows with boxShadow instead of shadow props', () => { | ||
| const originalPlatform = Platform.OS; | ||
| Platform.OS = 'web'; | ||
|
|
||
| try { | ||
| const { getByTestId } = render( | ||
| <Surface elevation={5} testID="surface-test"> | ||
| {null} | ||
| </Surface> | ||
| ); | ||
|
|
||
| const styles = StyleSheet.flatten( | ||
| getByTestId('surface-test').props.style | ||
| ); | ||
|
|
||
| expect(styles).toMatchObject({ | ||
| boxShadow: '0px 8px 12px rgba(0, 0, 0, 0.3)', | ||
| }); | ||
| expect(styles).not.toHaveProperty('shadowColor'); | ||
| expect(styles).not.toHaveProperty('shadowOpacity'); | ||
| expect(styles).not.toHaveProperty('shadowOffset'); | ||
| expect(styles).not.toHaveProperty('shadowRadius'); | ||
| } finally { | ||
| Platform.OS = originalPlatform; | ||
| } |
| const getShadowColor = (shadowColor: ColorValue, shadowOpacity: number) => | ||
| color(typeof shadowColor === 'string' ? shadowColor : 'black') | ||
| .alpha(shadowOpacity) | ||
| .rgb() | ||
| .string(); |
There was a problem hiding this comment.
If a non-string is received on Web, it should throw an error as it's a user error instead of defaulting to black.
| const getBoxShadowValue = (elevation: number, shadowColor: ColorValue) => | ||
| `0px ${shadowLayers[0].height[elevation]}px ${ | ||
| shadowLayers[0].shadowRadius[elevation] | ||
| }px ${getShadowColor(shadowColor, elevation ? 0.3 : 0)}`; |
There was a problem hiding this comment.
for interpolations, this is doing color manipulation multiple times even though the color is not changing. Move this to the web branch and assign it to a variable, then reuse the variable in the shadow.
Summary
Testing